<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
%>
<%@ page import="java.util.List,com.resource.allocator.EMF,
com.resource.allocator.model.Resource,javax.persistence.*,
com.google.appengine.api.datastore.KeyFactory"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="cache-control" content="no-cache" />
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet" />
<title>Resources list</title>
</head>
<body>
    <div class="container">
        <%
        EntityManager em = EMF.get().createEntityManager();
        try{
        Query q = em.createQuery("select r from Resource r order by r.capacity desc");
        List<Resource> resourceList = q.getResultList();
        
            if (resourceList == null) {
                
        		out.println("<pre>There's no resource found. Try to create one OR ");
                out.println("<a href=\"/resourcesController\"><i class=\"icon-refresh\"></i> refresh</a> </pre>");
            } else {
        %>
        <h3>Resources: </h3>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>action</th>
                    <th>Name</th>
                    <th>Capacity</th>
                    <th>Skill</th>
                </tr>
            </thead>
            <tbody>
                <%
                    for (Resource r : resourceList) {
                %>
                <tr>
                    <td><a
                        href="/resourcesController?action=edit&key=<%=KeyFactory.keyToString(r.getKey()) %>"
                    ><i class="icon-edit"></i></a></td>
                    <td><%=r.getFirstName() + " " + r.getLastName()%></td>
                    <td><%=r.getCapacity()%></td>
                    <td><%=r.getSkills()%></td>
                </tr>
                <%
                    }
                    }
        }finally{
            em.close();
        }
                %>
            </tbody>
        </table>
        <br/>
        <a href="/resourcesController?action=create">
        <i class="icon-plus"></i>Create Resource.</a>
        
    </div>
</body>
</html>